﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;

namespace Infrastructure.Aspect.Services.Serialization
{
    public class NetDataContractSerializerService : ISerializationService
    {
        public byte[] Serialization(object target)
        {
            var ser = new NetDataContractSerializer();
            using(var mem = new MemoryStream())
	        {
                ser.WriteObject(mem, target);
                mem.Flush();
                return mem.ToArray();
	        }            
        }

        public T DesSerialization<T>(byte[] target)
        {
            var ser = new NetDataContractSerializer();
            using (var mem = new MemoryStream(target))
            {
                var result = (T)ser.ReadObject(mem);
                return result;
            }            
        }
    }
}
